package com.ctshk.sapp.train.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.train.req.CjTrainNumberReq;
import com.ctshk.rpc.train.service.CJTrainProductService;
import com.ctshk.rpc.train.service.ITrainNumberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 港铁售票流程
 * </p>
 */
@Api(value = "港铁售票流程", tags = "港铁售票流程")
@RestController
@RequestMapping("/cj-train-number")
public class CjTrainSaleController extends BaseController {

    @DubboReference
    private ITrainNumberService trainNumberService;

    @DubboReference
    private CJTrainProductService cjTrainProductService;

    @ApiOperation(value = "港铁保存站点信息", notes = "港铁保存站点信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "港铁保存站点信息", operDesc = "港铁保存站点信息")
    @GetMapping("/saveTrainStationCode")
    public Result saveTrainStationCode() {
        cjTrainProductService.saveTrainStationCode();
        return Result.success();
    }

    @ApiOperation(value = "港铁车次列表", notes = "港铁车次列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "港铁车次列表", operDesc = "港铁车次列表")
    @PostMapping("/getTrainNumberList")
    public Result getTrainNumberList(@RequestBody CjTrainNumberReq cjTrainNumberReq) {
        return Result.success(cjTrainProductService.getTrainNumberList(cjTrainNumberReq.getStrFmStatCde(),
                cjTrainNumberReq.getStrToStatCde(), cjTrainNumberReq.getBoardingStationName(), cjTrainNumberReq.getAlightingStationName(),
                cjTrainNumberReq.getDtmDeptDte()));
    }

    @ApiOperation(value = "港铁车次座位", notes = "港铁车次座位")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "港铁车次座位", operDesc = "港铁车次座位")
    @PostMapping("/getTrainNumberSeatList")
    public Result getTrainNumberSeatList(@RequestBody CjTrainNumberReq cjTrainNumberReq) {
        return Result.success(cjTrainProductService.getTrainNumberSeatList(cjTrainNumberReq.getTrainNum(),
                cjTrainNumberReq.getStrFmStatCde(), cjTrainNumberReq.getStrToStatCde(),
                cjTrainNumberReq.getDtmDeptDte()));
    }

    @ApiOperation(value = "列出车次的车厢及车层", notes = "列出车次的车厢及车层")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "列出车次的车厢及车层", operDesc = "列出车次的车厢及车层")
    @PostMapping("/listCoachAvalByTrn")
    public Result listCoachAvalByTrn(@RequestBody CjTrainNumberReq cjTrainNumberReq) {
        return Result.success(cjTrainProductService.listCoachAvalByTrn(cjTrainNumberReq.getTrainNum(),
                cjTrainNumberReq.getStrFmStatCde(), cjTrainNumberReq.getStrToStatCde(),
                cjTrainNumberReq.getDtmDeptDte(), cjTrainNumberReq.getSeatClsCode()));
    }

    @ApiOperation(value = "座位图资料查询", notes = "座位图资料查询")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "座位图资料查询", operDesc = "座位图资料查询")
    @PostMapping("/listSeatPlanByCoach")
    public Result listSeatPlanByCoach(@RequestBody CjTrainNumberReq cjTrainNumberReq) {
        return Result.success(cjTrainProductService.listSeatPlanByCoach(cjTrainNumberReq.getTrainNum(),
                cjTrainNumberReq.getStrFmStatCde(), cjTrainNumberReq.getStrToStatCde(),
                cjTrainNumberReq.getDtmDeptDte(), cjTrainNumberReq.getSeatClsCode(), ""));
    }

    @ApiOperation(value = "港铁开始售票", notes = "港铁开始售票")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "港铁开始售票", operDesc = "港铁开始售票")
    @GetMapping("/begin")
    public Result begin() {
        return Result.success(cjTrainProductService.begin());
    }

    @ApiOperation(value = "港铁取消售票", notes = "港铁取消售票")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "港铁开始售票", operDesc = "港铁开始售票")
    @GetMapping("/rollBack/{strTxnID}")
    public Result rollBack(@PathVariable("strTxnID") String strTxnID) {
        return Result.success(cjTrainProductService.rollBack(strTxnID));
    }

    @ApiOperation(value = "自动选座", notes = "自动选座")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "自动选座", operDesc = "自动选座")
    @PostMapping("/selSeatBySystem")
    public Result selSeatBySystem(@RequestBody CjTrainNumberReq req) {
        return Result.success(cjTrainProductService.selSeatBySystem(req.getStrTxnID(),
                req.getStrFmStatCde(), req.getStrToStatCde(), req.getDtmDeptDte(), req.getTrainNum(),
                req.getSeatClsCode(), req.getTickTypeCde(), req.getAdultNum(), req.getChildNum()));
    }

    @ApiOperation(value = "列出已選座位", notes = "列出已選座位")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "自动选座", operDesc = "自动选座")
    @PostMapping("/listReservedSeat")
    public Result listReservedSeat(@RequestBody CjTrainNumberReq req) {
        return Result.success(cjTrainProductService.listReservedSeat(req.getStrTxnID()));
    }


    @ApiOperation(value = "更改實名資料", notes = "更改實名資料")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "自动选座", operDesc = "自动选座")
    @PostMapping("/updateRealNameInfo")
    public Result updateRealNameInfo(@RequestBody CjTrainNumberReq req) {
        return Result.success(cjTrainProductService.updateRealNameInfo(req.getStrTxnID(), req.getTrainNum(),
                req.getIntCoachSeq(), req.getIntSeatSeq(), req.getDtmTrnDeptDte(), req.getIntDocType(),
                req.getStrDocID(), req.getStrDocHolderName(), req.getIntDeckSeq()));
    }

    @ApiOperation(value = "付款", notes = "付款")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "付款", operDesc = "付款")
    @PostMapping("/payment")
    public Result payment(@RequestBody CjTrainNumberReq req) {
        return Result.success(cjTrainProductService.payment(req.getStrTxnID(), req.getAmount(),
                req.getStrCustName(), req.getStrCustTel()));
    }

    @ApiOperation(value = "确认交易", notes = "确认交易")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "付款", operDesc = "付款")
    @PostMapping("/mtdCommit")
    public Result mtdCommit(@RequestBody CjTrainNumberReq req) {
        return Result.success(cjTrainProductService.mtdCommit(req.getStrTxnID()));
    }
}
